package com.chapter15.generic_;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * @author 宋鑫宇
 * @version 1.0
 * 泛型入门
 */
public class Generic01 {
    public static void main(String[] args) {
        //表示存放在ArrayList中的元素是Dog类型
        HashMap<String,Student> s = new HashMap<String,Student>();
        s.put("1",new Student("jack"));
        s.put("2",new Student("mary"));
        s.put("3",new Student("smith"));
        Set<String> strings = s.keySet();
        for (String student : strings) {
            System.out.println(student + "=" + s.get(student));
        }
        Set<Map.Entry<String, Student>> entries = s.entrySet();
        Iterator<Map.Entry<String, Student>> iterator = entries.iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, Student> next =  iterator.next();
            System.out.println(next);
        }

    }
}
class Student{
    public String name;

    public Student(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                '}';
    }
}

